<template>
	<view class="index c0 f16 p-r bf" style="padding-bottom: 180rpx ;" v-if="carList && carList.goodsList"
		@click.stop="czClose">
		<vipInfo :payVip="payVip" @handvipUser="vipUser = true" @vip="vip" />
		<view class="p10 bf">
			<view class="f-bt mt10 f-y-c">
				<view class="flex f-y-c">
					<view class="f20 wei">商品合计</view>
					<view class="f20 wei crb">￥{{carList.totalMoney}}</view>
					<view class="f11 c9 t-d-l" v-if="carList.lineMoney>carList.totalMoney">￥{{carList.lineMoney}}</view>
					<view class="f11 c9 ml10">
						({{carList.generalGoods && carList.generalGoods.length}}种商品)共{{carList.totalGoodsNum}}件</view>
				</view>
				<view class="f12 mr10 c0 wei" @click.stop="multipleShow = !multipleShow">操作</view>
			</view>
			<view v-if="form.diningType==6 && carList.discountsPlus && carList.discountsPlus.length">
				<block v-for="(v,i) in carList.discountsPlus" :key="i">
					<view v-if="v.type=='wipeZero' || v.type=='manualDiscount'" class="f-bt c6 f12 mt10 f-y-c">
						<view class="f-g-1 f-bt">
							<view>{{v.activityName}}</view>
							<view>-￥{{v.money}}</view>
						</view>
						<view class="f-g-0 cz">
							<u--text v-if="v.type=='wipeZero'" text="撤销" align="right" size="13" color="#FA463D"
								@click="cancleWipe('wipeZero')"></u--text>
						</view>
					</view>
				</block>
			</view>
			<view class="bf mt20 flex bb1 pb10"
				v-if="form.diningType==6 && carList.inStoreConfig && carList.inStoreConfig.style==2">
				<view class="f14">就餐方式：</view>
				<u-radio-group v-model="packaging" placement="row" @change="changePack" size="16" icon-color="#000">
					<u-radio :activeColor="subColor" label="店内就餐" :name="0" :labelSize="16" :iconSize="14"
						:customStyle="{marginRight: '50rpx'}"></u-radio>
					<u-radio :activeColor="subColor" label="打包带走" :name="1" :labelSize="16" :iconSize="14"></u-radio>
				</u-radio-group>
			</view>
			<view class="mt20 f-bt bb1 pb10">
				<view class="flex f-g-1">
					<view class="f14">整单备注：</view>
					<view v-if="isRemark" class="f-1 p-0-10 f14"
						style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" @click="remark=true">
						{{params.notes}}
					</view>
					<view v-else class="f14 c9 f-1" @click="remark=true">请输入特殊要求</view>
				</view>
				<view class="f-g-0 f-y-c" @click="remark=true"><u-icon name="arrow-right" size="12"></u-icon></view>
			</view>
		</view>
		<cz :show="multipleShow" mode="multiple" :type="form.diningType" @op="handOrder" :v="form" :carList="carList" @showStop="showStop">
		</cz>
		<view class="p10 bf page mt10">
			<view class="f-bt" v-if="carList.generalGoods && carList.generalGoods.length">
				<view class="f12 c9">当前商品</view>
				<view class="f12 crb" @click="clearCar">清空</view>
			</view>
			<view class="dfa goods p-r" v-for="(item,index) in carList.generalGoods" :key="index">
				<view class="w65 c3 dfa">
					<view class="f14">
						<view @click.stop="namedl(item,index)" class="flex">
							<view class="uTag mr5 f-c f12 cf" v-if="item.pack">包</view>
							{{item.goods.name}}
						</view>
						<view class="flex f-w f12 c9">
							<view v-if="item.attrData && item.attrData.spec">[{{ item.attrData.spec }}]</view>
							<view v-if="item.attrData && item.attrData.attr">[{{ item.attrData.attr }}]</view>
							<view v-if="item.attrData && item.attrData.matal">{{ item.attrData.matal }}</view>
							<view v-if="item.setMealData && item.setMealData.length">
								<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
									<text v-if="cv.attrData && cv.attrData.attr" class="ml10">[{{ cv.attrData.attr }}]</text>
									<text v-if="cv.attrData && cv.attrData.matal" class="ml10">[{{ cv.attrData.matal }}]</text>
								</view>
							</view>
						</view>
					</view>
					<cz :show="singleShow" v-if="index==cName" :left="-12" :top="70" :sRight="-25"
						:type="form.diningType" mode="single" :v="item" @op="handsOrder"></cz>
				</view>
				<view class="f-1 dfbc">
					<view class="f-g-1 f-bt">
						<view class="">
							<view class="f14 c0 wei6 mr10">￥{{item.money}}</view>
						</view>
						<view class="flex f-y-c">
							<view class="jh f-c jhb" @tap.stop="handcar({g: item,addwz: -1,})">
								<text class='iconfont icon-jianhao f26 nowei c0'></text>
							</view>
							<view class="number f16">{{item.num}}</view>
							<view class="jh f-c" :style="{background:subColor}"
								@tap.stop="handcar({g: item,addwz: 1,})">
								<text class='iconfont icon-jiahao1 f26 nowei'></text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mt30" v-if="carList.discountsGoods && carList.discountsGoods.length">
				<view class="f12 c9">优惠商品</view>
				<view class="dfa goods p-r" v-for="(item,index) in carList.discountsGoods" :key="index">
					<view class="w65 c3 dfa">
						<view class="f14">
							<view @click.stop="nameDisdl(item,index)" class="flex f-y-c">
								<view class="uTag mr5 f-c f12 cf" v-if="item.pack">包</view>
								{{item.goods.name}}
								<view class="tlabel ml5" :style="{color:'#FD8906',borderColor:'#FD8906'}" v-if="item.discountLabel">{{item.discountLabel}}</view>
							</view>
							<view class="flex f-w f12 c9">
								<view v-if="item.attrData && item.attrData.spec">[{{ item.attrData.spec }}]</view>
								<view v-if="item.attrData && item.attrData.attr">[{{ item.attrData.attr }}]</view>
								<view v-if="item.attrData && item.attrData.matal">{{ item.attrData.matal }}</view>
								<view v-if="item.setMealData && item.setMealData.length">
									<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
										<text v-if="cv.attrData && cv.attrData.attr" class="ml10">[{{ cv.attrData.attr }}]</text>
										<text v-if="cv.attrData && cv.attrData.matal" class="ml10">[{{ cv.attrData.matal }}]</text>
									</view>
								</view>
							</view>
						</view>
						<cz :show="singleDisShow" v-if="index==cDisName" :left="-12" :top="70" :sRight="-25"
							:type="form.diningType" mode="singleDis" :v="item" @op="handDisOrder"></cz>
					</view>
					<view class="f-1 dfbc">
						<view>
							<view class="c9 f14">￥{{item.money}}</view>
							<view class="c9 f12 t-d-l">￥{{item.sellMoney}}</view>
						</view>
						<view class="flex f-y-c">
							<view class="jh f-c jhb" @tap.stop="handDis({g: item,addwz: -1,})">
								<text class='iconfont icon-jianhao f26 nowei c0'></text>
							</view>
							<view class="number f16">{{item.num}}</view>
							<view class="jh f-c" :style="{background:subColor}"
								@tap.stop="handDis({g: item,addwz: 1,})">
								<text class='iconfont icon-jiahao1 f26 nowei'></text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mt30" v-if="form.diningType==4 && carList.prentGoods">
				<view class="f12 c9">以下为已点商品</view>
				<view class="dfa goods" v-for="(item,index) in carList.prentGoods" :key="index">
					<view class="w65 c3 dfa">
						<view class="f14 c9">{{item.name}}</view>
					</view>
					<view class="f-1 dfbc">
						<text class="c9 f14">x{{item.num}}</text>
						<view class="dfa">
							<view>
								<view class="f14 c0 wei6 mr10">￥{{item.money}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="carList.tableMoney > 0">
				<view class="dfa goods">
					<view class="w65 c3 dfa">
						<view class="f14 c9">{{carList.tableFormat || '服务费'}}</view>
					</view>
					<view class="f-1 dfbc">
						<text class="c9 f14">x{{carList.tableNum}}</text>
						<view class="f14 c0 wei6 mr10">￥{{carList.tableMoney}}</view>
					</view>
				</view>
			</view>
			
			<discounts :dl="carList" :pl="params" :couponId='couponId'></discounts>
		</view>
		<view class="but bf pb10 w100">
			<view v-if="carList.diningType==6" class="f-g-1 tac dfa"
				:style="{background: subColor,borderRadius: '50rpx',margin:'20rpx'}">
				<view class="w100 f16 c0 p10" @click="savePay">下单并支付</view>
			</view>
			<view v-else class="f-g-1 tac f-bt buts" :style="{borderColor:subColor}">
				<view class="w100 f16 c0 p10 f-g-1" @click="savePay">下单并支付</view>
				<view class="w100 f16 c0 p10 f-g-1" @click="saveOrder" :style="{background: subColor}">立即下单</view>
			</view>
		</view>

		<u-modal :show="remark" title="整单备注" :showCancelButton="true" cancelText="取消" confirmColor="#FD8906"
			@cancel="remark=false" @close="remark=false" @confirm="addremark" :negativeTop="200">
			<view class="slot-content f-1" style="padding: 2rpx;">
				<view class="flex">
					<view class="f-g-1 f-w flex">
						<view v-for="(v,i) in reasonConfig.orderNotes" :key="i" class="kj c3 f12" @click="kjcx(v)">{{v}}</view>
					</view>
				</view>
				<view class="mt10" style="border: 2rpx solid #d6d6d6;">
					<u--textarea placeholder="请输入订单备注" border="none" :customStyl="{background:'#f3f3f3'}"
						v-model="params.notes">
					</u--textarea>
				</view>
			</view>
		</u-modal>

		<u-modal :show="vipUser" :negativeTop="200" title="会员查询" confirmText="查询" showCancelButton
			confirmColor="#FD8906" cancelColor="#000" @confirm="search" @cancel="vipUser = false"
			@close="vipUser = false" zoom>
			<view class="slot-content">
				<u--input v-model="phone" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手机号" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>
		<giveGoods ref="giveRef" @save="checkOut" :v="form" mode="single"></giveGoods>
		<disGoods ref="disRef" @save="checkOut" :v="form" mode="single"></disGoods>
		<pay ref="Pay" :ps="pay" :payVip="payVip" :v="carList" @changePay="changePay" @goPay="goPay" @print="print"
			:onOverlay="false"></pay>
		<turntable ref="turntableRef" @save="checkOut" :v="form"></turntable>
		<member ref="memberRef" @chooseMember="chooseMember" />
		<view class="acshet">
			<u-action-sheet :actions="moreList" @select="selectClick" :closeOnClickOverlay="true" :closeOnClickAction="false" @close="moreShow = false" :show="moreShow" cancelText='取消'></u-action-sheet>
		</view>
		<u-modal :show="coinRy" :negativeTop="200" title="任意金额" confirmText="确定" showCancelButton
			confirmColor="#FD8906" cancelColor="#000" @confirm="disconMoney('custom', customMoney)" @cancel="coinRy = false"
			@close="coinRy = false" zoom>
			<view class="slot-content">
				<u--input v-model="customMoney" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手动抹零金额" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>
		<disOrder ref="disOrderRef" @save="checkOut" :v="form" mode="multiple"></disOrder>
		<freeOf ref="freeOfRef" @save="freeOfOut" :v="form" mode="multiple"></freeOf>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
	} from 'vuex'
	import cz from "../components/cz.vue"
	import giveGoods from "../components/giveGoods.vue"
	import disGoods from "../components/disGoods.vue"
	import pay from '@/components/pay/pay.vue'
	import turntable from "../components/turntable.vue"
	import member from '@/components/user/member.vue';
	import vipInfo from './components/vipInfo.vue';
	import disOrder from "../components/disOrder.vue"
	import freeOf from "../components/freeOf.vue"
	import Discounts from './components/discounts.vue'
	import {
		throttle
	} from '@/common/handutil.js'
	export default {
		components: {
			cz,
			giveGoods,
			disGoods,
			pay,
			turntable,
			member,
			vipInfo,
			disOrder,
			freeOf,
			Discounts,
		},
		data() {
			return {
				subColor: uni.getStorageSync('subject_color'),
				show: false,
				payVip: {},
				remark: false,
				isRemark: false,
				form: {},
				params: {
					userId: 0,
					notes: '',
					money: '',
					payType: 0,
					printSwitch: 2,
				},
				packaging: 0,
				carList: {},
				orderList: [],
				vipUser: false,
				phone: '',
				showPay: false,
				pay: {
					money: '',
					payType: 0,
					authCode: 0,
					payUserId: 0,
					printSwitch: 2,
					costomPayId: 0,
				},
				orderInfo: {},
				multipleShow: false,
				cName: 0,
				cDisName: 0,
				singleShow: false,
				singleDisShow: false,
				peoShow: false,
				cForm: {},
				moreShow:false,
				coinRy:false,
				customMoney:'',
				moreList: [
					{
						name:'抹分',
						value:'F'
					},
					{
						name:'抹角',
						value:'J'
					},
					{
						name:'抹元',
						value:'Y'
					},
					{
						name:'任意金额',
						value:'R'
					}
				],
				couponId: 0,
			}
		},
		async onLoad(options) {
			if (options.id) {
				this.id = options.id
				await this.getTableInfo()
				this.checkOut()
			} else {
				this.form.diningType = 6
				this.form.storeId = this.storeId
				this.form.id = 0
				this.checkOut()
			}
			this.getReasonConfig()
			// uni.setNavigationBarColor({
			//     frontColor: '#000',
			//     backgroundColor: uni.getStorageSync('subject_color')
			// })
			uni.$on('payorder', (e) => {
				if (e.hasOwnProperty('hbInfo')) {
					if (e.type == 1) {
						this.couponId = e.hbInfo ? e.hbInfo.id : 0
						this.useCoupon()
					}
				}
				console.log('payorderEl', e)
			})
		},
		computed: {
			...mapState({
				storeId: state => state.storeId,
				reasonConfig: state => state.config.reasonConfig,
			}),
		},
		onShow() {
			if (this.form.id >= 0 && this.orderInfo && !this.orderInfo.orderSn) {
				this.checkOut()
			}
		},
		onUnload() {
			uni.$off('payorder');
		},
		methods: {
			...mapMutations(["setConfig"]),
			async getTableInfo() {
				let {
					data
				} = await this.beg.request({
					url: `${this.api.inTabel}/${this.id}`,
				})
				this.form = data ? data : {}
			},
			async getCar() {
				let {
					data
				} = await this.beg.request({
					url: this.api.cart,
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
					}
				})
				this.carList = data ? data : {},
					this.orderList = data.goodsList ? data.goodsList : []
			},
			async getReasonConfig() {
				let {
					data
				} = await this.beg.request({
					url: this.api.config,
					data: {
						ident: 'reasonConfig'
					}
				})
				this.setConfig({
					name: 'reasonConfig',
					data,
				})
			},
			namedl(v, i) {
				// if (this.carList.diningType == 6) return
				this.cName = i
				this.cForm = v
				this.singleShow = !this.singleShow
				this.singleDisShow = false
				this.multipleShow = false
			},
			nameDisdl(v, i) {
				if (v.discountType == 6) return
				this.cDisName = i
				this.cForm = v
				this.singleDisShow = !this.singleDisShow
				this.singleShow = false
				this.multipleShow = false
			},
			async checkOut() {
				let {
					data
				} = await this.beg.request({
					url: this.api.checkout,
					// method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						userId: this.params.userId,
						notes: this.params.notes,
						check: 'false',
					}
				})
				this.carList = data ? data : {},
					this.orderList = data.goodsList ? data.goodsList : [],
					this.packaging = data.packaging
					this.couponId = data.couponId ? data.couponId : 0
				if(data.prentOrder && data.prentOrder.notes){
					this.isRemark = true
					this.params.notes = data.prentOrder.notes
				} 
			},
			async useCoupon(){
				let {
					data
				} = await this.beg.request({
					url: this.api.cCoupon,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						userId: this.params.userId,
						couponId: this.couponId,
					}
				})
				// this.carList = data ? data : {}
			},
			async changePack(e) {
				let {
					data
				} = await this.beg.request({
					url: this.api.goodsPackAll,
					method: 'POST',
					data: {
						type: e == 0 ? 'back' : '',
						tableId: this.form.id,
						storeId: this.form.storeId,
						diningType: this.form.diningType,
					},
				})
				this.packaging = e
				this.checkOut()
			},
			async handcar(p) {
				try {
					let {
						data
					} = await this.beg.request({
						url: this.api.cart,
						method: 'POST',
						data: {
							spuId: p.g.spuId,
							specMd5: p.g.specSwitch ? p.g.specInfo && p.g.specInfo.specMd5 : p.g.specMd5 || p.g
								.singleSpec.specMd5,
							attrData: p.g.specMd5 ? p.g.attrData : (p.g.specSwitch || p.g.attrSwitch || p.g
								.materialSwitch) ? {
								spec: p.g.specSwitch && p.g.ggdata ? p.g.ggdata : '',
								attr: p.g.attribute,
								matal: p.g.jldata,
								material: p.g.material,
							} : {},
							num: p.addwz,
							storeId: this.form.storeId,
							tableId: this.form.id,
							diningType: this.form.diningType,
						}
					})
					this.checkOut()
				} catch (e) {
					console.log(e)
				}
			},
			async handDis(p) {
				if(p && p.g && p.g.discountType>=6){
					this.handcar(p)
				}else{
					let {
						data
					} = await this.beg.request({
						url: this.api.give,
						method: 'POST',
						data: {
							goods: [{
								id: p.g.id,
								num: p.addwz
							}],
							type: 'give',
							storeId: this.form.storeId,
							tableId: this.form.id,
							diningType: this.form.diningType,
						}
					})
					this.checkOut()
				}
			},
			async handOrder(type) {
				let n = '',
					a = ''
				if (type == 'give') {
					uni.navigateTo({
						url: `/pages/order/orders/give?diningType=${this.form.diningType}&storeId=${this.storeId}&id=${this.form.id}`
					})
				} else if (type == 'turntable') {
					this.$refs['turntableRef'].open(type)
				} else if (type == 'parallel') {
					this.$refs['turntableRef'].open(type)
				}else if(type =='coin'){
					this.moreShow = true
				}else if(type=='discountOrder'){
					this.$refs['disOrderRef'].open(type)
				}else if(type=='cancleWipe'){
					this.cancleWipe('manualDiscountd')
				}else if(type=='freeOf'){
					this.$refs['freeOfRef'].open(type)
				}
				this.multipleShow = false
			},
			selectClick(e){
				 this.moreShow = false
				if(e.value=='R'){
					this.coinRy = true
				}else{
					this.disconMoney(e.value)
				}
			},
			async disconMoney(type, discount) {
				let {
					data
				} = await this.beg.request({
					url: this.form.orderSn ? `${this.api.orderWipeZero}/${this.form.orderSn}` : this.api
						.inStoreWipeZero,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						type,
						discount,
					}
				})
				this.coinRy = false
				this.moreShow = false
				this.checkOut()
			},
			async cancleWipe(type) {
				let {
					data
				} = await this.beg.request({
					url: this.form.orderSn ? `${this.api.orderCancelDiscount}/${this.form.orderSn}` : this
						.api.cancelDiscount,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						storeId: this.form.storeId,
						tableId: this.form.id,
						type,
					}
				})
				this.checkOut()
			},
			freeOfOut(){
				uni.switchTab ({
					url: `/pages/index/index`
				})
			},
			async handsOrder(type) {
				let n = '',
					a = ''
				if (type == 'give') {
					this.$refs['giveRef'].open(this.cForm)
				} else if (type == 'discount') {
					this.$refs['disRef'].open(this.cForm)
				} else if (type == 'pack') {
					let ids = []
					ids.push(this.cForm && this.cForm.id)
					let {
						data
					} = await this.beg.request({
						url: this.api.goodsPack,
						method: 'POST',
						data: {
							ids,
							type: this.cForm && this.cForm.pack ? 'back' : '',
						}
					})
					this.checkOut()
				}
				this.singleShow = false
			},
			async handDisOrder(type) {
				if (type == 'pack') {
					let ids = []
					ids.push(this.cForm && this.cForm.id)
					let {
						data
					} = await this.beg.request({
						url: this.api.goodsPack,
						method: 'POST',
						data: {
							ids,
							type: this.cForm && this.cForm.pack ? 'back' : '',
						}
					})
					this.singleDisShow = false
					this.checkOut()
				} else {
					let n = '',
						a = ''
					switch (type) {
						case 'backGive':
							n = "你确定取消赠菜吗";
							a = 'give';
							break;
						case 'backDis':
							n = "你确定取消打折吗";
							a = 'give';
							break;
						case 'backSub':
							n = "你确定取消立减吗";
							a = 'give';
							break;
					}
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: this.api[a],
									method: "POST",
									data: {
										goods: [{
											id: this.cForm.id,
											num: this.cForm.num
										}],
										type: 'back',
										storeId: this.form.storeId,
										tableId: this.form.id,
										diningType: this.form.diningType,
									}
								})
								this.singleDisShow = false
								this.checkOut()
							}
						}
					})
				}
			},
			async savePay() {
				if (this.carList.diningType == 4) {
					if (this.orderInfo && this.orderInfo.orderSn) {
						this.pay.money = this.carList.money
						this.$refs['Pay'].open(this.pay)
					} else {
						let {
							data
						} = await this.beg.request({
							url: this.api.inOrder,
							method: 'POST',
							data: {
								diningType: this.form.diningType,
								tableId: this.form.id,
							}
						})
						this.orderInfo = data
						if (data && data.orderSn) {
							this.pay.money = this.carList.money
							// if(this.carList.diningType==4 && this.carList.payType==2){
							// 	this.pay.printSwitch = [1]
							// }
							this.$refs['Pay'].open(this.pay)
						}
					}
				} else {
					this.pay.money = this.carList.money
					this.$refs['Pay'].open(this.pay)
				}

			},
			async goPay() {
				if (this.carList.diningType == 4) {
					let {
						data,
						msg
					} = await this.beg.request({
						url: `${this.api.inPay}/${this.orderInfo.prentOrderSn || this.orderInfo.orderSn}`,
						method: 'POST',
						data: this.pay
					})
					uni.showToast({
						title: msg,
						icon: 'none',
					});
					if (data && data) {
						// #ifdef MP-WEIXIN 
							uni.reLaunch({
								url: `/pages/order/orders/index`
							})
						// #endif
						// #ifndef MP-WEIXIN
							uni.switchTab ({
								url: `/pages/index/index`
							})
						// #endif
						// uni.redirectTo({
						// 	url: `/pages/order/detail?id=${this.orderInfo.prentOrderSn || this.orderInfo.orderSn}&type=inStore`
						// })
					}
				} else {
					this.fastOrder()
				}
			},
			print(n) {

			},
			saveOrder: throttle(async function(e) {
				let {
					data
				} = await this.beg.request({
					url: this.api.inOrder,
					method: 'POST',
					data: {
						diningType: this.form.diningType,
						tableId: this.form.id,
					}
				})
				this.orderInfo = data
				if (data && data.orderSn) {
					// #ifdef MP-WEIXIN
						uni.reLaunch({
							url: `/pages/order/orders/index`
						})
					// #endif
					// #ifndef MP-WEIXIN
						uni.switchTab ({
							url: `/pages/index/index`
						})
					// #endif
				}
			}, 500),
			fastOrder: throttle(async function(e) {
				this.pay.diningType = this.form.diningType
				this.pay.tableId = this.form.id
				let {
					data
				} = await this.beg.request({
					url: this.api.inOrder,
					method: 'POST',
					data: this.pay
				})
				this.orderInfo = data
				if (data && data.orderSn) {
					uni.redirectTo({
						url: `/pages/order/indetail?id=${data.prentOrderSn || data.orderSn}&type=inStore`
					})
				}
			}, 500),
			vip() {
				this.payVip = {}
				this.params.userId = 0
				if (this.orderInfo && !this.orderInfo.orderSn) {
					this.checkOut()
				}
			},
			clickNote() {
				this.remark = true
			},
			changePay(e) {
				if (e == 'authCode') {
					this.vipUser = false
					this.pay.payType = 'authCode'
					this.params.payType = 'authCode'
					var that = this
					uni.scanCode({
						onlyFromCamera: true,
						success: async function(res) {
							uni.showLoading({
								title: 'loading...'
							})
							if (res.result) {
								that.pay.authCode = res.result
								if (that.carList.diningType == 4) {
									that.goPay()
								} else {
									that.fastOrder()
								}
								uni.hideLoading()
							} else {
								uni.hideLoading()
							}
						},
					});
				} else if (e == 'balance') {
					this.pay.payType = 'balance'
					this.params.payType = 'balance'
					if (this.payVip && this.payVip.id) {
						this.phone = this.vipUser.mobile
					} else {
						this.vipUser = true
					}
				} else if (e == 'cash') {
					this.vipUser = false
					this.pay.payType = 'cash'
					this.params.payType = 'cash'
				}else{
					this.pay.costomPayId = e
					this.pay.payType = 'costomPay'
					this.params.payType = 'costomPay'
				}
			},
			async search() {
				const reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				if (this.phone) {
					this.vipUser = false
					uni.showLoading({
						title: 'loading...'
					})
					let {
						data
					} = await this.beg.request({
						url: this.api.cMember,
						data: {
							mobile: this.phone
						},
					})
					if (data && data.list.length) {
						uni.hideLoading()
						if (data.list.length > 1) {
							this.$refs['memberRef'].open(data.list)
						} else {
							// if (this.vipUserType == 2) {
							// 	this.payVip = data.list[0]
							// 	this.pay.payUserId = data.list[0].id
							// 	console.log(this.payVip)
							// } else {
							this.payVip = data.list[0]
							this.pay.payUserId = data.list[0].id
							this.params.userId = data.list[0].id
							if (this.orderInfo && !this.orderInfo.orderSn) {
								this.checkOut()
							}
							this.phone = ''
							// }
						}
					} else {
						uni.hideLoading()
						uni.$u.toast('暂未查到用户信息');
					}
				} else {
					uni.$u.toast('请输入正确的手机号');
				}
			},
			chooseMember(e) {
				this.payVip = e
				this.pay.payUserId = e.id
				this.params.userId = e.id
				if (this.orderInfo && !this.orderInfo.orderSn) {
					this.checkOut()
				}
				this.phone = ''
			},
			addremark() {
				if (this.params.notes != '') {
					this.isRemark = true
				}
				this.allRemark()
				this.remark = false
			},
			async allRemark(e) {
				let {
					data
				} = await this.beg.request({
					url: this.api.goodsAllRemark,
					method: 'POST',
					data: {
						notes: this.params.notes,
						tableId: this.form.id,
						storeId: this.form.storeId,
						diningType: this.form.diningType,
					},
				})
				this.carList = data ? data : {},
				this.orderList = data.goodsList ? data.goodsList : [],
				this.packaging = data.packaging
			},
			clearCar() {
				uni.showModal({
					title: '提示',
					content: '清空当前购物车将重新点餐',
					success: async (res) => {
						if (res.confirm) {
							let {
								msg
							} = await this.beg.request({
								url: this.api.clearCart,
								method: 'DELETE',
								data: {
									tableId: this.form && this.form.id || 0,
									storeId: this.form.storeId,
									diningType: this.form.diningType,
								}
							})
							if (this.form.diningType == 6) {
								uni.redirectTo({
									url: `/pages/order/orderMeal/index?diningType=${this.form.diningType}`
								})
							} else {
								uni.redirectTo({
									url: `/pages/order/orderMeal/index?id=${this.form.id}`
								})
							}

						}
					}
				});
			},
			czClose() {
				this.multipleShow = false
				this.singleShow = false
				this.singleDisShow = false
			},
			showStop() {
				this.multipleShow = true
			},
			kjcx(v){
				this.params.notes = v
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100%;
		overflow: auto;
	}

	.w65 {
		width: 60%;
	}

	.but {
		height: 140rpx;
		position: fixed;
		bottom: 0;

		.butt {
			padding: 10rpx 0;
			width: 170rpx;
		}
	}

	.goods {
		padding: 30rpx 0;
		border-bottom: 2rpx solid #f5f5f5;
	}

	.tlabel {
		padding: 2rpx 4rpx;
		font-size: 20rpx;
		font-weight: normal;
		color: #FD8906;
		border-radius: 6rpx;
		margin-right: 10rpx;
		border: 2rpx solid #f5f5f5;
	}

	.number {
		width: 60rpx;
		text-align: center;
	}

	.buts {
		// position: fixed;
		// bottom: 40rpx;
		// left: 50%;
		// transform: translateX(-50%);
		margin: 0 40rpx;
		height: 80rpx;
		border: 2rpx solid #fff;
		border-radius: 50rpx;
		overflow: hidden;

	}

	.slot-content {
		width: 100%;
	}

	/deep/ .u-button__text {
		font-size: 17px !important;
	}

	.f40 {
		font-size: 40rpx;
	}

	.f42 {
		font-size: 42rpx;
	}

	.uTag {
		background: #1c9945;
		width: 36rpx;
		height: 36rpx;
		border-radius: 6rpx;
	}
	
	.kj{
		border: 2rpx solid #e7e7e7;
		margin-right: 10rpx;
		margin-bottom: 10rpx;
		padding: 6rpx;
		border-radius: 4rpx;
	}
	
	.cz {
		width: 80rpx;
	}
</style>